﻿/*
 * Customers.cs
 * 
 * Copyright © 2007 Aptech Software Limited. All rights reserved.
 */

using System;

namespace CSharp
{
    class Customers
    {
        public static void Test(string[] args)
        {
            int[] age = {1, 2, 3};
            bool[] gender = new bool[3];
            string[] city = new string[3];
            string[] customerName = new string[3];

            string cityName;
            int total = 0;
            int i = 0;

            do
            {
                // Accepting the details of customer using do-//while loop
                Console.Write("Enter the name of customer : ");
                customerName[i] = Console.ReadLine();

                Console.Write("Enter the age : ");
                age[i] = Convert.ToInt32(Console.ReadLine());

                Console.Write("Enter gender [M/F] : ");
                char g = Console.ReadLine()[0];
                gender[i] = (g == 'M' || g == 'm');

                Console.Write("Enter city : ");
                city[i] = Console.ReadLine();

                Console.WriteLine();
                i++;
            } while (i < customerName.Length);

            Console.WriteLine("Customer Details : ");
            Console.WriteLine("Name          \tAge \tGender \tCity");
            for (i = 0; i < customerName.Length; i++)
            {
                WriteCustomer(customerName[i], age[i], gender[i], city[i]);
            }

            // Hiển thị tên các khách hàng
            Console.WriteLine("\nNames of Customers : ");

            foreach (string names in customerName)
            {
                Console.WriteLine("{0} ", names);
            }

            // Nhập vô tên thành phố muốn tìm khách hàng
            Console.Write("\nEnter the name of city whose records you want to view : ");
            cityName = Console.ReadLine();

            // Tìm kiếm khách hàng tại thành phố được nhập vô
            Console.WriteLine("\nCustomer Details ({0}) : ", cityName);
            Console.WriteLine("Name          \tAge \tGender \tCity");
            i = 0;
            while (i < customerName.Length)
            {
                if (city[i] == cityName)
                {
                    WriteCustomer(customerName[i], age[i], gender[i], city[i]);
                    total++;
                }
                i++;
            }

            // Displaying the total number of customers according to the choice entered
            Console.WriteLine("No. of customers in {0} : {1}", cityName, total);
        }

        private static void WriteCustomer(string name, int age, bool gender, string city)
        {
            Console.Write("{0} \t{1} \t", name, age);
            Console.Write(gender ? "Male \t" : "Female \t");
            Console.WriteLine("{0}", city);
        }
    }
}
